/******************************************************************************

  Copyright (C), 2012-2016, ZHANGYA

 ******************************************************************************
  File Name     : main.c
  Version       : Initial Draft
  Author        : zhangya
  Created       : 2024/4/17
  Last Modified :
  Description   : main.c
  Function List :
  History       :
  1.Date        : 2024/4/17
    Author      : zhangya
    Modification: Created file

******************************************************************************/

#include "main.h"
#include "board.h"
#include "app.h"

/*--------------------------------------------------------------------*
 * $external variables                           *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $external routine prototypes                  *
 *--------------------------------------------------------------------*/
#define MS_TICK                          (system_core_clock / 1000U)

/*--------------------------------------------------------------------*
 * $internal routine prototypes                  *
 *--------------------------------------------------------------------*/
const char _make_data[] = __DATE__;
const char _make_time[] = __TIME__;

/*--------------------------------------------------------------------*
 * $project-wide global variables                *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $module-wide global variables                 *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $constants                                    *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $macros                                       *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $routines' implementations                    *
 *--------------------------------------------------------------------*/

/*****************************************************************************
 Prototype    : main
 Description  : main
 Input        : void  
 Output       : None
 Return Value : 
 Calls        : 
 Called By    : 
 
  History        :
  1.Date         : 2024/5/8
    Author       : zhangya
    Modification : Created function

*****************************************************************************/
int main(void)
{
#ifdef IAP_EN
	nvic_vector_table_set(NVIC_VECTTAB_FLASH, 0x8000);
#endif

	system_clock_config();
	crm_adc_clock_div_set(CRM_ADC_DIV_4);

	nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
	systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
	SysTick_Config(MS_TICK);

	debug_init();
	DEBUG_STR("board init\r\n");

	board_init();
	app_init();

	DEBUG_STR("app start\r\n");
	for ( ; ; )
	{
		timer_handle();
		app_handle();
	}
}
